<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />

</head>


<body>
    <!-- <ul class="aui-list aui-list-in div1" style="background:#fff;width:150px;position:absolute;display:none;z-index:100;" id="list1">

    </ul> -->
    <section class="aui-grid" >

        <div class="aui-row" id="list">
        </div>

    </section>
</body>
<script type="text/template" id="template">

  {{~it:value:index}}
  <div class="aui-col-xs-6 goods" style="padding:0 2px 5px;background:#f1f1f1" tapmode onclick="fnOpenWareWin('{{=value.id}},{{=value.source}}');">
     <div style="background-color:#ffffff">
      <img src="{{= fnSiteUrl(value.thumb)}}" alt="" width="200px" height="200px">
      <div class="aui-row" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;padding:0 10px;margin-top:0.3rem">
          {{= value.title}}<div class="aui-label aui-label-shike01">赠</div>
      </div>
      <p style="overflow:hidden;"><div class="aui-label aui-label-warning aui-label-outlined">包邮</div> <span style="text-decoration:line-through;color:#ff4285" style="font-size:0.5rem">{{= value.mod_price }}</span> &nbsp;&nbsp;&nbsp;
          <span style="font-size:0.6rem">仅剩{{= value.number}}份</span></p>
      </div>
  </div>
  {{~}}

</script>
<script type="text/template" id="template1">

    {{~it:value:index}}
    <li class="aui-list-item">
        <div class="aui-list-item-inner aui-list-item-arrow " style="white-space:nowrap; overflow:hidden;" onclick="fnPitchOn();">
            {{= value.catname}}
        </div>
    </li>

    {{~}}
</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    apiready = function() {
      fnGetGoodsList(); //发送请求加载商品数据分配到模板
      initRefresh();
      initEventListenter();
      fnGetCategory();
    };
    //获取分组列表
    function fnGetCategory(){
      api.ajax({
          //http://test.renqishike.com/index.php?m=api&c=appnew&a=goodslists&catid=0&is_point=0&is_vip=0&mod=trial&orderby=id&orderway=desc&page=1&trial_type=0
          url: SITE_URL+"index.php?m=api&c=appnew&a=goods_categorylists",
          method: 'GET',
      }, function(ret, err) {
          fnUpdateGoodsList1(ret);
        //alert(JSON.stringify(ret));
      })
    }
    function fnUpdateGoodsList1(ret) {

        var list = $api.byId('list1'); //获取节点
        //var str={"array":["banana","apple","orange"]};
        // 1. 编译模板函数
        var tempFn = doT.template($api.byId('template1').innerHTML); //找到模板多次使用
        // 2. 多次使用模板函数
        var resultText = tempFn(ret.lists);

        $api.append(list, resultText);

        //$api.html(list, resultText);

    }
    function fnAnimationLeft() {
        $(".div1").animate({
            width: 'toggle'
        });

    }
    function fnPitchOn(){
      $(".div1").animate({
          width: 'toggle'
      });
    }
    count = "";
    page = 1;

    function fnGetGoodsList(load_more) {
        api.showProgress({
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (load_more) {
            page++;
        } else {
            page = 1;
        }

        api.ajax({
            //http://test.renqishike.com/index.php?m=api&c=appnew&a=goodslists&catid=0&is_point=0&is_vip=0&mod=trial&orderby=id&orderway=desc&page=1&trial_type=0
            url: SITE_URL+"index.php?m=api&c=appnew&a=goodslists&catid=0&is_point=0&is_vip=0&mod=trial&orderby=id&orderway=desc&page=" + page + "&trial_type=0",
            method: 'GET',
        }, function(ret, err) {
            if (ret) {

                //每十条是一组数据；
                count = ret.count; //查到符合要求的数据总条数；
                pageTot = Math.ceil(count / 10);
                //判断总的页数

                if (pageTot <=page) {
                    //如果大于；
                    var notice = $api.byId('pushStatus'); //获取节点
                    $api.html(notice, "没有啦！");
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    fnUpdateGoodsList(ret, load_more);
                } else {
                    api.refreshHeaderLoadDone(); //下拉刷新隐藏
                    fnUpdateGoodsList(ret, load_more);
                }

            } else {
                api.alert({
                    msg: JSON.stringify(err)
                });
            }
        });
    }
    //数组分配到模板；
    function fnUpdateGoodsList(ret, load_more) {

        var list = $api.byId('list'); //获取节点
        //var str={"array":["banana","apple","orange"]};
        // 1. 编译模板函数
        var tempFn = doT.template($api.byId('template').innerHTML); //找到模板多次使用
        // 2. 多次使用模板函数
        var resultText = tempFn(ret.lists);
        if (load_more) {
            $api.append(list, resultText);
        } else {
            $api.html(list, resultText);
        }
        api.hideProgress();
        //$api.html(list, resultText);

    }

    function fnUpdateSlide() {
        var banner = $api.byId('aui-slide3');
        api.imageCache({ //图片缓存，防止卡顿
            url: wareTypeList[api.pageParam.wareTypeIndex].banner.url
        }, function(ret, err) {
            if (ret) {
                //alert(JSON.stringify(ret));
                if (ret && ret.status) {
                    banner.src = ret.url;
                }
            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function fnUpdateBanner() {
        var banner = $api.byId('banner');
        api.imageCache({ //图片缓存，防止卡顿
            url: wareTypeList[api.pageParam.wareTypeIndex].banner.url
        }, function(ret, err) {
            if (ret) {
                //alert(JSON.stringify(ret));
                if (ret && ret.status) {
                    banner.src = ret.url;
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }
    //下拉刷新，松开刷新
    function initRefresh() {
        api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            fnGetGoodsList();
        });
    }



    //打开商品详情页面
    function fnOpenWareWin(wareId_) {
        api.openWin({
            name: 'ware',
            url: './ware.html',
            pageParam: {
                wareId: wareId_
            }
        });
    }

    function initEventListenter() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 300
            }
        }, function(ret, err) {
            fnGetGoodsList(true);
        });
    }
</script>


</html>
